﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfApplication5.ViewModels"
        xmlns:hello="clr-namespace:WpfApplication5"
        xmlns:Models="clr-namespace:WpfApplication5.Models" x:Class="WpfApplication5.MainWindow"
        Title="MainWindow">

    <Window.Resources>
        
        <system:Boolean x:Key="FalseValue">False</system:Boolean>
        <Color x:Key="AccentColor">#1ba1e2</Color>
        <SolidColorBrush x:Key="ItemBackgroundHover" Color="#dddddd" />
        <SolidColorBrush x:Key="ItemTextHover" Color="#333333" />
        <SolidColorBrush x:Key="ItemBackgroundSelected" Color="{DynamicResource AccentColor}" />
        <SolidColorBrush x:Key="ItemTextSelected" Color="#ffffff" />
        <SolidColorBrush x:Key="ItemTextDisabled" Color="#919191" />
        <SolidColorBrush Color="#d6d4d4" x:Key="BorderBrush" />

        <hello:FunctionParameterValueConverter x:Key="parameterConverter" />
        <hello:TreeViewLineConverter x:Key="LineConverter"/>
        <hello:FunctionSampleConverter x:Key="SampleConverter" />
        <hello:FunctionParamerConverter x:Key="ParamerConverter" />

        <Style TargetType="{x:Type Border}" x:Key="BorderTreeStyle">
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush SpreadMethod="Repeat" StartPoint="0,5" EndPoint="5,0" MappingMode="Absolute">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="Blue" Offset="0"/>
                            <GradientStop Color="Blue" Offset="0.2"/>
                            <GradientStop Color="Transparent" Offset="0.4"/>
                            <GradientStop Color="Transparent" Offset="0.6"/>
                            <GradientStop Color="Blue" Offset="0.8"/>
                            <GradientStop Color="Blue" Offset="1"/>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Grid x:Name="Root" Background="Transparent" Width="12" Height="12">
                            <Border x:Name="OuterBorder" BorderBrush="Black" CornerRadius="3"
                                    BorderThickness="1" Opacity="0.5" Background="Transparent" />
                            <Grid Margin="3">
                                <Path x:Name="UncheckedVisual" UseLayoutRounding="False"
                                              HorizontalAlignment="Center"  Stretch="Uniform"
                                              Data="M0,4 L4,4 L4,0 L6,0 L6,4 L10,4 L10,6 L6,6 L6,10 L4,10 L4,6 L0,6 z"
                                              VerticalAlignment="Center"
                                              Opacity="1" Fill="Black" />
                            </Grid>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Data" TargetName="UncheckedVisual" Value="M0,4 L10,4 L10,6 L0,6 z"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="TreeViewItemFocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type TextBlock}" x:Key="CaptionStyle">
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="32" />
            <Setter Property="Margin" Value="10,5" />
        </Style>

        <Style TargetType="{x:Type TextBlock}" x:Key="TitleStyle">
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="16" />
            <Setter Property="Margin" Value="10,5" />
        </Style>

        <Style TargetType="{x:Type TextBlock}" x:Key="lefttext_style">
            <Setter Property="Foreground" Value="#1fa3eb" />
            <Setter Property="FontSize" Value="11" />
            <Setter Property="Margin" Value="0,2,0,5" />
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="VerticalAlignment" Value="Top" />
        </Style>

        <Style TargetType="{x:Type TextBlock}" x:Key="righttext_style" >
            <Setter Property="Foreground" Value="#333333" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Margin" Value="0 0 0 4" />
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="FontWeight" Value="Light" />
        </Style>

        <Style TargetType="{x:Type Border}" x:Key="separator_style">
            <Setter Property="BorderBrush" Value="#FFFFFF" />
            <Setter Property="BorderThickness" Value="0,0,0,0" />
            <Setter Property="Height" Value="2" />
            <Setter Property="Margin" Value="0,10" />
        </Style>

        <Style TargetType="{x:Type TreeView}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Top" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Padding" Value="2" />
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="1,1" StartPoint="0.2,0">
                        <GradientStop Color="#FFB1B1B1" Offset="0.391"/>
                        <GradientStop Color="#46FFFFFF" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeView}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver" />
                                    <VisualState x:Name="Pressed" />
                                    <VisualState x:Name="Disabled" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Unfocused" />
                                    <VisualState x:Name="Focused" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ValidationStates">
                                    <VisualState x:Name="Valid" />
                                    <VisualState x:Name="InvalidUnfocused">

                                    </VisualState>
                                    <VisualState x:Name="InvalidFocused">

                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="InnerBorder" BorderThickness="0" CornerRadius="4"
                                    Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                                    Padding="0">
                                <ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}" Background="{x:Null}"
                                              BorderBrush="Transparent" BorderThickness="0" Margin="0">
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="MinHeight" Value="10" />
            <Setter Property="FontWeight" Value="Normal" />
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment"  Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Padding"  Value="4,1"/>
            <Setter Property="FocusVisualStyle"  Value="{StaticResource TreeViewItemFocusVisual}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid Background="Transparent" Margin="{TemplateBinding Padding}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="4" Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <Grid x:Name="HoverBorder" Opacity="0" IsHitTestVisible="False">
                                <Border BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        Background="{TemplateBinding Background}" />
                            </Grid>
                            <StackPanel x:Name="Bd" Orientation="Horizontal" Grid.Column="1">
                                <Line x:Name="lineH" Stroke="{TemplateBinding Foreground}"
                                      StrokeThickness="1" X1="0" X2="10"
                                      Y1="0" Y2="0" StrokeDashArray="1 1.5" Stretch="UniformToFill"
                                      VerticalAlignment="Center" HorizontalAlignment="Left"                          
                                      UseLayoutRounding="True" IsHitTestVisible="False"/>
                                <StackPanel Orientation="Horizontal">
                                    <ToggleButton x:Name="Expander"
                                      Style="{StaticResource ExpandCollapseToggleStyle}"
                                      IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                                      ClickMode="Press"/>
                                    <Border 
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        Padding="{TemplateBinding Padding}"
                                        SnapsToDevicePixels="true">
                                        <ContentPresenter x:Name="PART_Header" Margin="0"
                                              ContentSource="Header"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                    </Border>
                                </StackPanel>

                            </StackPanel>

                            <ItemsPresenter x:Name="ItemsHost"  Grid.Row="1" Grid.Column="1"
                                        Grid.ColumnSpan="2"/>
                            <Border x:Name="BorderLine" Grid.Row="1" Grid.Column="1" IsHitTestVisible="False">
                                <Line x:Name="line" Stroke="{TemplateBinding Foreground}"
                                      StrokeThickness="1" X1="0" X2="0" Y1="0" Y2="2" StrokeDashArray="1 2" Stretch="UniformToFill"
                                      Width="0.5" VerticalAlignment="Stretch" HorizontalAlignment="Left" UseLayoutRounding="False" />
                            </Border>

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="false">
                                <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
                            </Trigger>
                            <Trigger Property="HasItems" Value="false">
                                <Setter TargetName="Expander" Property="Visibility" Value="Hidden"/>
                            </Trigger>
                            <Trigger SourceName="Bd" Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemBackgroundHover}"/>
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextHover}"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemBackgroundSelected}"/>
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextDisabled}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel/>
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="HyperlinkLikeButton" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}" />
            <Setter Property="Cursor" Value="Hand" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ControlTemplate.Resources>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <Setter Property="TextDecorations" Value="Underline" />
                                    </Style>
                                </ControlTemplate.Resources>
                                <ContentPresenter />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="HyperlinkTextBlock" TargetType="{x:Type TextBlock}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}" />
            <Setter Property="Cursor" Value="Hand" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="TextDecorations" Value="Underline" />
                </Trigger>
            </Style.Triggers>
        </Style>
        
        <DataTemplate x:Key="FunctionSampleTemplate">
            <WrapPanel Orientation="Horizontal" Margin="2 2 2 2">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Image VerticalAlignment="Top">
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Tag}" Value="CFP">
                                        <Setter Property="Image.Source" Value="cfp.png" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Tag}" Value="CFH">
                                        <Setter Property="Image.Source" Value="cfh.png" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>
                    <Button Style="{StaticResource HyperlinkLikeButton}" Click="Button_Click_1" Margin="5 0 0 5" Grid.Column="1">
                        <TextBlock Text="{Binding Sample}" Padding="2 1" TextWrapping="Wrap" Style="{StaticResource HyperlinkTextBlock}" />
                    </Button>
                </Grid>
            </WrapPanel>
        </DataTemplate>
        
        <DataTemplate x:Key="FunctionParameterTemplate">
            <WrapPanel Orientation="Horizontal" Margin="2 2 2 2">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MaxWidth="10" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding No}"/>
                    <TextBlock Text="{Binding ParameterInfo}" Padding="2 1" TextWrapping="Wrap"  Margin="5 0 0 5" Grid.Column="1" />
                </Grid>
            </WrapPanel>
        </DataTemplate>
        
        <DataTemplate x:Key="FunctionInfoDetailsDataTemplate">
            <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  
                    BorderBrush="{StaticResource BorderBrush}" CornerRadius="10"
                    BorderThickness="1" 
				DataContext="{Binding SelectedItem, ElementName=xTreeView}">
                <Border.Background>
                    <ImageBrush ImageSource="chinascope.png" Opacity="0.05" />
                </Border.Background>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Border BorderBrush="{StaticResource BorderBrush}" BorderThickness="0 0 0 0">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding FunctionInfo.Code}" Style="{StaticResource CaptionStyle}"
                                       TextWrapping="Wrap"/>
                        </StackPanel>
                    </Border>

                    <StackPanel Margin="10 0" Grid.Row="1">
                        <Border BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1">
                            <TextBlock Text="参数释义" Style="{StaticResource TitleStyle}" Margin="0 7"  />
                        </Border>
                        <TextBlock Text="{Binding FunctionInfo.DescCN}" TextWrapping="Wrap" />
                        <Border Style="{StaticResource separator_style}" />                        

                        <Border BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1">
                            <TextBlock Text="相关变量" Style="{StaticResource TitleStyle}" Margin="0,7" />
                        </Border>
                        <ItemsControl ItemsSource="{Binding Parameters,Converter={StaticResource ParamerConverter}}"
                                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                      ItemTemplate="{StaticResource FunctionParameterTemplate}">
                        </ItemsControl>
                        <!--<ListBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="4" Grid.Column="1"
                                         IsSynchronizedWithCurrentItem="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                         ItemsSource="{Binding Parameters,Converter={StaticResource ParamerConverter}}"                                          
                                         ItemTemplate="{StaticResource FunctionParameterTemplate}"
                                         BorderThickness="0">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="{x:Type ListBoxItem}">
                                    <Style.Triggers>
                                        <Trigger Property="IsSelected" Value="True" >
                                            <Setter Property="Background" Value="{x:Null}" />
                                        </Trigger>
                                        <Trigger Property="IsEnabled"  Value="True">
                                            <Setter Property="Background" Value="{x:Null}" />
                                        </Trigger>
                                        <Trigger Property="Visibility" Value="Visible">
                                            <Setter Property="Background" Value="{x:Null}" />
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>-->
                        <Border Style="{StaticResource separator_style}" />


                        <Border BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1">
                            <TextBlock Text="适用函数及完整函数表达式" Style="{StaticResource TitleStyle}" Margin="0,7" />
                        </Border>
                        <ItemsControl ItemsSource="{Binding FunctionInfo.Sample,Converter={StaticResource SampleConverter}}"        
                                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                      ItemTemplate="{StaticResource FunctionSampleTemplate}">
                        </ItemsControl>
                        <!--<ListBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="4" Grid.Column="1"
                                         IsSynchronizedWithCurrentItem="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                         ItemsSource="{Binding FunctionInfo.Sample,Converter={StaticResource SampleConverter}}"                                          
                                         ItemTemplate="{StaticResource FunctionSampleTemplate}"
                                         BorderThickness="0">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="{x:Type ListBoxItem}">
                                    <Style.Triggers>
                                        <Trigger Property="IsSelected" Value="True" >
                                            <Setter Property="Background" Value="{x:Null}" />
                                        </Trigger>
                                        <Trigger Property="IsEnabled"  Value="True">
                                            <Setter Property="Background" Value="{x:Null}" />
                                        </Trigger>
                                        <Trigger Property="Visibility" Value="Visible">
                                            <Setter Property="Background" Value="{x:Null}" />
                                        </Trigger>
                                    </Style.Triggers>
                                    <Style.Resources>
                                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                                    </Style.Resources>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>-->
                        <Border Style="{StaticResource separator_style}" />

                    </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>

        <DataTemplate x:Key="FunctionCategoryDetailsDataTemplate">
            <Image Source="chinascope.png" Stretch="Fill" Opacity="0.05" />
        </DataTemplate>


        <hello:MasterDetailTemplateSelector x:Key="DetailsTemplateSelector" 
                                            FunctionInfoTemplate="{StaticResource FunctionInfoDetailsDataTemplate}" FunctionCategoryTemplate="{StaticResource FunctionCategoryDetailsDataTemplate}"/>

        <Style x:Key="ButtonCancelStyle" TargetType="{x:Type Button}">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="SnapsToDevicePixels" Value="True" />
            <Setter Property="Content" Value="r" />
            <Setter Property="FontFamily" Value="Marlett" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Background" Value="#bababa" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border Width="15" Height="15">
                            <Border.Background>
                                <DrawingBrush Viewport="0,0,1,1" Stretch="Fill">
                                    <DrawingBrush.Drawing>
                                        <GeometryDrawing Brush="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
                                            <GeometryDrawing.Geometry>
                                                <EllipseGeometry RadiusX="1" RadiusY="1" />
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Border.Background>
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" Value="#9a9a9a" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="SearchTextBoxStyle" TargetType="{x:Type TextBox}">
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Margin" Value="3,0,0,2" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalAlignment}">
                            <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type hello:SearchBox}">
            <Setter Property="Background" Value="White" />
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
            <Setter Property="MinWidth" Value="150"/>
            <Setter Property="MinHeight" Value="20"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Focusable" Value="True" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type hello:SearchBox}">
                        <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="12">
                            <Grid Margin="5,2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Path Width="15" Height="15" Stroke="#737373" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center">
                                    <Path.Data>
                                        <GeometryGroup>
                                            <LineGeometry StartPoint="10,10" EndPoint="14,14" />
                                            <EllipseGeometry Center="6,6" RadiusX="5" RadiusY="5" />
                                        </GeometryGroup>
                                    </Path.Data>
                                </Path>
                                <TextBox x:Name="PART_Textbox" 
                                     Text="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" 
                                     Grid.Column="1" 
                                     Style="{StaticResource SearchTextBoxStyle}"
                                     hello:WatermarkAdorner.Text="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}" />
                                <Button x:Name="PART_Cancel" Grid.Column="2" Style="{StaticResource ButtonCancelStyle}" />
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding Text, ElementName=PART_Textbox}" Value="">
                                <Setter TargetName="PART_Cancel" Property="Visibility" Value="Hidden" />
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>

    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Left">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Border BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" CornerRadius="10">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <Border HorizontalAlignment="Left">
                    <!--<TextBlock Text="Customer Data" Style="{StaticResource TitleStyle}" />-->
                    <hello:SearchBox Width="296" HorizontalAlignment="Stretch" BorderThickness="1" BorderBrush="{StaticResource BorderBrush}" Margin="1,0,0,1" />
                </Border>

                <TreeView x:Name="xTreeView" Grid.Row="1"
                          ItemsSource="{Binding Categories}">
                    <TreeView.Resources>
                        <HierarchicalDataTemplate
                                  DataType="{x:Type local:FunctionCategoryViewModel}"
                                  ItemsSource="{Binding Children}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Category.NameCN}" 
                                           ToolTip="{Binding RelativeSource={RelativeSource Self},Path=Text}" 
                                            />
                            </StackPanel>

                        </HierarchicalDataTemplate>

                        <DataTemplate DataType="{x:Type local:FunctionInfoViewModel}">
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Left">
                                <Image Width="12" Height="12" Source="Images\function.png" Margin="-8 0 0 0" />
                                <TextBlock Text="&gt;"/>
                                <TextBlock Text="{Binding FunctionInfo.NameCN}" 
                                           ToolTip="{Binding RelativeSource={RelativeSource Self},Path=Text}"
                                           />
                            </StackPanel>
                        </DataTemplate>
                    </TreeView.Resources>
                </TreeView>
            </Grid>
        </Border>

        <hello:ContentControlEx VerticalAlignment="Stretch" Grid.Column="2" HorizontalAlignment="Stretch"
                                        DataContext="{Binding SelectedItem, ElementName=xTreeView}"
                                        Content="{Binding}" TemplateSelector="{StaticResource DetailsTemplateSelector}" />
    </Grid>
</Window>
